-- socket下载文件
require "socket"
function download(host,file)
    local f = io.open("test.html","w+") -- 打开文件
    local c = assert(socket.connect(host,80)) --返回socket对象
    c:send("GET "..file.." HTTP/1.0\r\n\r\n") -- 发送请求
    while true do
        --receive: 正常返回字符串,错误时返回nil和错误码(status),并返回出错前读取的信息(partial)
        local s,status,partial = c:receive(1024) -- 一次接受1k
        f:write(s or partial)
        if status == "closed" then
            break
        end

    end
    c:close()
    f:close()
end
host = "www.w3.org"
file ="/TR/REC-html32.html"
download(host,file)
